import request, { type ListResponse, type ListQuery } from "@/utils/request";

const EXPRESS_COMPANY_BASE_URL = "/api/internal/expressCompany";

const ExpressCompanyAPI = {
  getExpressCompanyList: (params: ListQuery) => {
    return request.get<any, ListResponse<ExpressCompanyType>>(`${EXPRESS_COMPANY_BASE_URL}/`, {
      params,
    });
  },
  getExpressCompanyDetail: (id: number) => {
    return request.get(`${EXPRESS_COMPANY_BASE_URL}/${id}/`);
  },
  createExpressCompany: (data: Partial<ExpressCompanyForm>) => {
    return request.post(`${EXPRESS_COMPANY_BASE_URL}/`, data);
  },
  updateExpressCompany: (data: Partial<ExpressCompanyForm>) => {
    return request.put(`${EXPRESS_COMPANY_BASE_URL}/${data.id}/`, data);
  },
  deleteExpressCompany: (id: number) => {
    return request.delete(`${EXPRESS_COMPANY_BASE_URL}/${id}/`);
  },
};

export type ExpressCompanyListQuery = {} & ListQuery;

/**
 * @description 快递公司类型
 * @property ems 国际邮政
 * @property domestic 国内
 * @property international 国际
 *
 */
export type ExpressCompanyTypeType = "ems" | "domestic" | "international";

export type ExpressCompanyType = {
  id: number;
  created_at: string;
  updated_at: string;
  name: string;
  code: string;
  type: "international";
  is_active: boolean;
};

export type ExpressCompanyForm = {
  id?: number;
  name: string;
  code: string;
  type: ExpressCompanyTypeType;
  is_active: boolean;
};

export default ExpressCompanyAPI;
